//
//  TextFields.m
//  Honda
//
//  Created by Wang.Xinlei on 4/25/13.
//  Copyright (c) 2013 HeninHoo. All rights reserved.
//

#import "TextFields.h"
#import "TextFieldDelegates.h"


@interface TextField ()

@property (retain, atomic) TextFieldDelegate * textFieldDelegate;

@end

@implementation TextField

@synthesize textFieldDelegate = _textFieldDelegate;

- (void)dealloc {
    SafeRelease(_textFieldDelegate);
    
    [super dealloc];
}

- (void)setDelegate:(id<UITextFieldDelegate>)delegate {
    self.textFieldDelegate.delegate = delegate;
}

- (void)awakeFromNib {
    self.leftView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, CGRectGetHeight(self.bounds))] autorelease];
    self.leftViewMode = UITextFieldViewModeAlways;
    
    self.backgroundColor = [UIColor whiteColor];
    self.borderStyle = UITextBorderStyleNone;
    self.textColor = HexRGB(0x666666);
    self.font = [UIFont systemFontOfSize:18];
    
    self.layer.borderColor = [UIColor colorWithWhite:(0xda / 255.0) alpha:1].CGColor;
    self.layer.borderWidth = 1;
    
    if (nil != self.delegate) {
        self.textFieldDelegate.delegate = self.delegate;
    }
    [super setDelegate:self.textFieldDelegate];
}

@end



@implementation NameFiled

- (void)awakeFromNib {
    self.textFieldDelegate = [NameFieldDelegate instance];
    [super awakeFromNib];
}

@end



@implementation NumberField

- (void)awakeFromNib {
    self.textFieldDelegate = [NumberFieldDelegate instance];
    self.keyboardType = UIKeyboardTypeNumberPad;
    [super awakeFromNib];
}

@end




@implementation DecimalField

- (void)awakeFromNib {
    self.textFieldDelegate = [DecimalFieldDelegate instance];
    self.keyboardType = UIKeyboardTypeNumberPad;
    [super awakeFromNib];
}

@end
